# -*- coding: utf-8 -*-
"""
Created on Fri Oct 21 22:17:23 2016

@author: zhiqiang
"""
from math import sqrt
def is_prime(num):#判断一个奇数是不是质数
    is_pri = True
    if num==3:
        return True
    for i in range(3,int(sqrt(num))+1,2):
        if num%i==0:
            return False
    return is_pri

def get_prime_factor(num,primes):
    primes_factor = list()
    temp = num
    for prime in primes:
        if prime>num/2:
            break
        while temp%prime==0:
            primes_factor.append(prime)
            temp = temp//prime    
    return primes_factor
import time
t0 = time.time()
num = 647
primes = [2]
for i in range(3,num,2):
    if is_prime(i):
        primes.append(i)
#print(primes)
counts = 0
while True:
    #首先判断是否是质数，如果是质数则加入质数列表并跳过进行下一个运算
    if num%2!=0 and is_prime(num):
        primes.append(num)
        num += 1
        counts = 0
        continue

    primes_factor = get_prime_factor(num,primes)
    if len(set(primes_factor))==4:
        counts +=1
        if counts==4:
            break
    else:
        counts=0
    num += 1
    primes_factor.clear()
print(num-3)
t1 = time.time()
print(t1-t0)

if __name__=="__main__":
    import math
    import time
    
    
    def is_prime(x):
        """ 质数判断 """
        if x == 1:
            return False
        if x == 2:
            return True
        assert math.floor(x) == x and x > 0
        x_sqrt = int(math.sqrt(x))
        l = [2]
        l.extend(range(3, x_sqrt + 1, 2))
        for i in l:
            if x % i == 0:
                return False
        return True
    
    
    def get_factor(x):
        """ 质数因子 """
        factor = []
        if is_prime(x):
            factor.extend([x])
            return factor
        xx_sqrt = int(math.sqrt(x))
        for i in range(2, xx_sqrt + 1):
            if x % i == 0:
                if i in factor_dict:
                    factor.extend(factor_dict[i])
                else:
                    factor_ = get_factor(i)
                    factor.extend(factor_)
                    factor_dict[i] = factor_
                j = x // i
                if j in factor_dict:
                    factor.extend(factor_dict[j])
                else:
                    factor_ = get_factor(j)
                    factor.extend(factor_)
                    factor_dict[j] = factor_
                break
        return factor
    
    
    t0 = time.time()
    n = 4
    consecutive_num = 2 * 3 * 5 * 7
    n_factors = 0
    factor_dict = dict()
    while 1:
        if len(set(get_factor(consecutive_num))) == n:
            n_factors += 1
            if n_factors == n:
                break
        else:
            n_factors = 0
        consecutive_num += 1
    print(consecutive_num - 3)
    t1 = time.time()
    print(t1 - t0)